<?php
define('APP_DEBUG', 1);
require '../bootstrap.php';

require CORE_PATH . "Cli.php";

if (!isset($_GET['op'])){
    echo '<p>带参数的请以GET方式传递</p>';
	echo '<a href="?op=cache">清理缓存文件</a>'.PHP_EOL;
    echo '<a href="?op=app">更新路由规则</a>'.PHP_EOL;
    echo '<a href="?op=cron">计划任务</a>'.PHP_EOL;
	exit;
}

$_SERVER['argv'][0] = 'clear.php';
if ($_GET['op']=='app'){
	$_SERVER['argv'][1] = 'app';
	$_SERVER['argv'][2] = 'sync';
}elseif($_GET['op']=='cache'){
    $_SERVER['argv'][1] = 'cache';
    $_SERVER['argv'][2] = 'cleanup';
}elseif($_GET['op']=='cron'){
    $_SERVER['argv'][1] = 'cron';
    $_SERVER['argv'][2] = 'run';
}elseif($_GET['op']=='php'){
	phpinfo();
	exit;
}
/*$i = 3;
foreach($_GET AS $key=>$value){
    if ($key == 'op') continue;
    $_SERVER['argv'][$i] = '--'.$key.'='.$value;
    $i++;
}*/

try{
	ob_start();
    $application = new Core\Cli();
    $application->run();
	$content = ob_get_contents();
	ob_end_clean();
	echo str_replace(PHP_EOL, "<br>", $content);
}catch (Exception $e){
    echo $e->getMessage();
}